import 'package:sainbainu/common/apis/comment_api.dart';
import 'package:sainbainu/common/models/request/comment_add_request.dart';
import 'package:sainbainu/common/models/request/pager_request.dart';
import 'package:sainbainu/common/models/response/comment_response.dart';

class CommentRepository {
  final CommentApi _commentApi;

  CommentRepository(this._commentApi);

  /// 评论列表
  Future<CommentListResponse> commentList(
    PagerRequest pagerRequest,
    int noteId,
  ) async {
    Map<String, dynamic> params = pagerRequest.toJson();
    params['noteId'] = noteId;

    var res = await _commentApi.commentList(params);
    return CommentListResponse.fromJson(res);
  }

  /// 回复列表
  Future<CommentListResponse> replyCommentList(
    PagerRequest pagerRequest,
    int commentId,
  ) async {
    Map<String, dynamic> params = pagerRequest.toJson();
    params['commentId'] = commentId;

    var res = await _commentApi.replyCommentList(params);
    return CommentListResponse.fromJson(res);
  }

  /// 评论新增
  Future<Map<String, dynamic>> commentAdd(
    CommentAddRequest commentAddRequest,
  ) async {
    var res = await _commentApi.commentAdd(commentAddRequest.toJson());
    return res;
  }

  /// 评论删除
  Future<Map<String, dynamic>> commentDel(int commentId) async {
    var res = await _commentApi.commentDel({'commentId': commentId});
    return res;
  }
}
